package com.lmh.graphdisease.repository;

import com.lmh.graphdisease.entity.DepartmentEntity;
import org.neo4j.driver.internal.value.NodeValue;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lmh
 * @desc
 * @date 2023/3/6
 */
@Repository
public interface DepartmentRepository extends Neo4jRepository<DepartmentEntity,Long> {

    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 查出当前科室的所有负责的疾病
     */
    @Query("MATCH(n:Disease)-[r:belongs_to]->(nn:Department) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<NodeValue> getBelongToDepartment(String name,int num);


    @Query("MATCH (n:Department) RETURN n SKIP $0 LIMIT $1")
    List<DepartmentEntity> getNumDepartment(int page, int size);

    @Query("MATCH (n:Department) RETURN count(*)")
    Integer getDepartmentNum();

    @Query("CREATE(f:Department {name:$0})")
    void addDepartment(String name);

    @Query("MATCH (f:Department) WHERE f.name = $0 RETURN f")
    DepartmentEntity getDepartmentByName(String name);

    @Query("MATCH(f:Department{name:$0}) DELETE f")
    void deleteByName(String name);

}
